home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (c) 1985 Martin Nohr and Tom Serface
- * All Rights Reserved
- *
- * Revision Date Description
- * -------- --------- --------------------------------------------
- *
- * Changes permission attributes on DOS files. Works somewhat like the
- * Unix version. You can use the HEX equivalent or enter =+- attribute
- * to change.
- * Valid Attributes Are:
- * 00 - Normal File
- * 01 - Read Only File
- * 02 - Hidden File
- * 04 - System File
- * 08 - Volume Label
- * 10 - SubDirectory
- * 20 - Archive File
- * You can mix any of these for example:
- * chmod 07 filespec1 filespec2 ... <CR>
- * Changes all of the files in filespec1 and filespec 2
- * to Read Only Hidden System Files 01+02+04.
- * The file attributes are in Hexidecimal.
- *
- * You can also modify attributes on a file by entering:
- * '=', '+' or '-' 'n'ormal, 'h'idden, 's'ystem,
- * 'r'ead only, 'w'riteable, 'a'rchive
- * ('w' is the opposite of 'r')
- * e.g., chmod +rhs filespec1 filespec2 ... <CR>
- *
- */
- #include <stdio.h>
- #include <fileFind.h>
-
- #define PLUS '+'
- #define MINUS '-'
- #define EQUAL '='
- #define EOS '\0'
- #define YES 1
- #define NO 0
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- char fspec[85],directory[85],outFile[128],*where;
- char *rindex(), *opts;
- struct DataArea DTA;
- int mods=0, changing=NO;
-
- opts=argv[1];
- if(*opts == PLUS || *opts == MINUS)
- changing=YES;
- else if(*opts == EQUAL) {
- mods=F_NORMAL;
- mods=Set(mods,opts);
- }
- else {
- while(*opts)
- if(!isdigit(*opts++))
- usage();
- sscanf(argv[1],"%x",&mods);
- }
- argc -= 2;
- argv += 2;
- while(argc--) {
- strcpy(fspec, *argv++);
-
- /* Set up the Data Transfer Address Structure */
- SetDta(&DTA);
- strcpy(directory,fspec);
- if((where=rindex(directory,'\\')) || (where=rindex(directory,':'))) {
- *(where+1)=EOS;
- }
- else {
- directory[0]=EOS;
- }
- if (findFirst(fspec,F_ALL)) {
- do {
- strcpy(outFile,directory);
- strcat(outFile,DTA.dta_name);
- if(changing) {
- GetMod(outFile,&mods);
- mods=Set(mods,opts);
- }
- if(ChMod(outFile,mods) != 0)
- printf("Change failed for %s\n",outFile);
- } while (findNext(F_ALL));
- }
- else
- printf("Changed failed for %s\n",fspec);
- }
- }
-
- usage()
- {
- printf("Valid Attributes Are:\n");
- printf(" 00 - Normal File\n");
- printf(" 01 - Read Only File\n");
- printf(" 02 - Hidden File\n");
- printf(" 04 - System File\n");
- printf(" 08 - Volume Label\n");
- printf(" 10 - SubDirectory\n");
- printf(" 20 - Archive File\n");
- printf("You can mix any of these for example:\n");
- printf(" chmod 07 filespec1 filespec2 ... <CR>\n");
- printf("Changes all of the files in filespec1 and filespec 2\n");
- printf("to Read Only Hidden System Files 01+02+04.\n");
- printf("The file attributes are in Hexidecimal.\n");
- printf("\nYou can also modify attributes on a file by entering:\n");
- printf("'=', '+' or '-' 'n'ormal, 'h'idden, 's'ystem,\n");
- printf(" 'r'ead only, 'w'riteable, 'a'rchive\n");
- printf(" ('w' is the opposite of 'r')\n");
- printf(" e.g., chmod +rhs filespec1 filespec2 ... <CR>\n");
- exit(1);
- }
-
- Set(mods,opts)
- int mods;
- char *opts;
- {
- int add;
-
- add=(*opts==PLUS || *opts==EQUAL);
- ++opts;
- while(*opts) {
- switch(tolower(*opts)) {
- case 'n':
- mods=0;
- break;
- case 'r':
- if(add)
- mods |= F_READ_ONLY;
- else
- mods &= ~F_READ_ONLY;
- break;
- case 'w':
- if(add)
- mods &= ~F_READ_ONLY;
- else
- mods |= F_READ_ONLY;
- break;
- case 'h':
- if(add)
- mods |= F_HIDDEN;
- else
- mods &= ~F_HIDDEN;
- break;
- case 's':
- if(add)
- mods |= F_SYSTEM;
- else
- mods &= ~F_SYSTEM;
- break;
- case 'a':
- if(add)
- mods |= F_ARCHIVE;
- else
- mods &= ~F_ARCHIVE;
- break;
- case 'd':
- if(add)
- mods |= F_DIRECTORY;
- else
- mods &= ~F_DIRECTORY;
- break;
- case 'l':
- if(add)
- mods |= F_LABEL;
- else
- mods &= ~F_LABEL;
- break;
- default:
- usage();
- }
- ++opts;
- }
- return(mods);
- }
-